<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib prefix="s" uri="/struts-tags" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<%@ taglib uri="/struts-tags" prefix="s"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <%@ include file="../jslib/jquerylib.jsp" %>
		 <link rel="stylesheet" type="text/css" href="<%=request.getContextPath() %>/jqGrid/css/jqgrid.css"></link>
	  <script type="text/javascript" src="<%=request.getContextPath() %>/jslib/lhgdialog/lhgcore.lhgdialog.min.js?skin=mac"></script>
	  <script type='text/javascript' src="<%=request.getContextPath() %>/jslib/My97DatePicker/WdatePicker.js" defer="defer"></script>
      <link href="<%=request.getContextPath() %>/web/style/layout.css" type="text/css" rel="stylesheet"/>
     <link rel="stylesheet" href="<%=request.getContextPath() %>/jslib/ztree/css/zTreeStyle/zTreeStyle.css" type="text/css"/>
     <script type="text/javascript" src="<%=request.getContextPath() %>/jslib/ztree/jquery.ztree.core-3.4.js"></script>
    <link rel="stylesheet" type="text/css" href="<%=request.getContextPath() %>/jslib/jquery-easyui-1.4.1/themes/default/easyui.css">
	<link rel="stylesheet" type="text/css" href="<%=request.getContextPath() %>/jslib/jquery-easyui-1.4.1/themes/icon.css">
	<link rel="stylesheet" type="text/css" href="<%=request.getContextPath() %>/jslib/jquery-easyui-1.4.1/demo.css">
	<script type="text/javascript" src="<%=request.getContextPath() %>/jslib/jquery-easyui-1.4.1/jquery.easyui.min.js"></script>
    <c:if test="${requestScope.message!=null}">
		<script type="text/javascript">
 	 		     alert('<c:out value="${requestScope.message}"></c:out>');
 	 		     window.close();
 		</script>
	</c:if>
	<style>
		.ui-jqgrid .ui-jqgrid-htable th div,.ui-jqgrid tr.ui-row-ltr td,.ui-jqgrid .ui-jqgrid-title ,.ui-paging-info,.ui-pg-table {font-size:12px;}
		.ui-jqgrid .ui-pg-input{height:18px;}
		.norecords {    	display:none;    font-weight: bold;    left: 30%;    margin: 5px;    padding: 6px;    position: absolute;    text-align: center;    top: 45%;    width: auto;    z-index: 102;}
	
	</style>
	
    <script type="text/javascript">
    var api = frameElement.api, W = api.opener;
    var stateValue="";
    var id="${ep.id}";
    $().ready(function(){
    	a();
    	$("#gridTableUpdate").jqGrid({
			url:'<%=request.getContextPath() %>/eepRelations!queryChooseEQU.action',
			datatype: "json",
			height: 80,
			width: 300, 
			autowidth: true, 
			colNames:['设备ID','适用设备名称','适用设备编号'],
			colModel:[
					{name:'eId',index:'eId', width:100, key:true,hidden:true,hidedlg:true}, 
					{name:'eName',index:'eName', width:180},
					{name:'eNo',index:'eNo', width:180}	
		],
		shrinkToFit:false,  
		autoScroll: false,
		sortname:'eId',
		sortorder:'desc',
		viewrecords:true,
		//multiselect: true, // 是否显示复选框
		multiboxonly : true, 
		//gridview: true,  //提升速度
		rownumbers: true,//显示行号
		rownumWidth: 30, //行号的宽度
		rowNum:15,
		rowList:[15,20,50,400,510],
		toolbar: [false,"top"],
		jsonReader: {
			root:"rows",		// 数据行（默认为：rows）
			page: "page",  	// 当前页
			total: "total",  // 总页数
			records: "records",  // 总记录数
			repeatitems : false		// 设置成false，在后台设置值的时候，可以乱序。且并非每个值都得设
		},
		pager:"#gridUpdatePager",
		loadComplete: function(xhr) {  
	        var rowNum = parseInt($(this).getGridParam("records"), 10);  
	        if (rowNum <= 0) {  
	           // alert("没有符合条件的记录！");  
	        }  
	    }  ,
		prmNames:{rows:"rows",page:"page",sort:"sidx",order:"sord",search:"search"},
		caption: "适用设备列表"
    });	
    	$("#gridTable").jqGrid({
			url:'<%=request.getContextPath() %>/eepRelations!queryReDataByEP.action?epId='+'${ep.id}',
			datatype: "json",
			height: 80,
			width: 300, 
			autowidth: true, 
			colNames:['设备ID','适用设备名称','适用设备编号'],
			colModel:[
					{name:'eId',index:'eId', width:100, key:true,hidden:true,hidedlg:true}, 
					{name:'eName',index:'eName', width:180},
					{name:'eNo',index:'eNo', width:180}	
		],
		shrinkToFit:false,  
		autoScroll: false,
		sortname:'eId',
		sortorder:'desc',
		viewrecords:true,
		//multiselect: true, // 是否显示复选框
		multiboxonly : true, 
		//gridview: true,  //提升速度
		rownumbers: true,//显示行号
		rownumWidth: 30, //行号的宽度
		rowNum:15,
		rowList:[15,20,50,400,510],
		toolbar: [false,"top"],
		jsonReader: {
			root:"rows",		// 数据行（默认为：rows）
			page: "page",  	// 当前页
			total: "total",  // 总页数
			records: "records",  // 总记录数
			repeatitems : false		// 设置成false，在后台设置值的时候，可以乱序。且并非每个值都得设
		},
		pager:"#gridPager",
		loadComplete: function(xhr) {  
			var re_records = $("#gridTable").getGridParam('records');	
	        if(re_records == 0 || re_records == null){		
	        if($(".norecords").html() == null){			
	        $("#gridTable").parent().append("<div class=\"norecords\">此备件没有分配适用设备！</div>");
	        		}		
	        $(".norecords").show();	} 
	    }  ,
		prmNames:{rows:"rows",page:"page",sort:"sidx",order:"sord",search:"search"},

		caption: "适用设备列表"
    });   
    	$('#closeBtn').click(function(){
    		api.close();
		});
    	var options = {
    	  	    url:'<%=request.getContextPath() %>/equipmentParts!updateEquipmentParts.action',
    	  	     beforeSubmit: function() {
    	   				return checking();
    	    			},
    	  	    dataType:'json',
    	  	    success: function(data) {
    	  	      if(data.result=='success'){
    				alert("更新成功！");
    				api.close();
    				W.refreshIt();
    	  	      }
    	  	    }};
    	$('#saveBtn').click(function(){
	    	  $('#pageFrom').ajaxSubmit(options);
	          return false;
       });
		
	});
	function a(){
		$("#equUpdate").hide();
		$("#equView").show();
		document.getElementById("epRemark").value ="${ep.epRemark}";
		document.getElementById("epLevel").value ="${ep.epLevel}";
		document.getElementById("epProperty").value ="${ep.epProperty}";
		document.getElementById("epStockstate").value ="${ep.epStockstate}";
	}
	function checking(){
    	var epStorehouse = $.trim($("#epStorehouse").val());
		var epCode = $.trim($("#epCode").val());
		var epName = $.trim($("#epName").val());
		var epBrand = $.trim($("#epBrand").val());
		var epSupplier = $.trim($("#epSupplier").val());
		var epAverageprice = $.trim($("#epAverageprice").val());
		var epCycle = $.trim($("#epCycle").val());
		var epMaxstock = $.trim($("#epMaxstock").val());
		var epMinstock = $.trim($("#epMinstock").val());
		var epStoragelocation = $.trim($("#epStoragelocation").val());
		var epMeasurementunit = $.trim($("#epMeasurementunit").val());
		var epApplicableequipment = $.trim($("#epApplicableequipment").val());
		if(epStorehouse ==null || epStorehouse == "" ){
			alert("仓库名称不能为空！");
			$("#epStorehouse").focus();
    		return false;
		}
		if(epCode ==null || epCode == "" ){
			alert("备件代码不能为空！");
			$("#epCode").focus();
    		return false;
		}
		if(epName ==null || epName == "" ){
			alert("备件名称不能为空！");
			$("#epName").focus();
    		return false;
		}
		if(epBrand ==null || epBrand == "" ){
			alert("备件品牌不能为空！");
			$("#epBrand").focus();
    		return false;
		}
		if(epSupplier ==null || epSupplier == "" ){
			alert("供应商名称不能为空！");
			$("#epSupplier").focus();
    		return false;
		}
		if(epAverageprice ==null || epAverageprice == "" ){
			alert("备件价格不能为空！");
			$("#epAverageprice").focus();
    		return false;
		}
		if(epCycle ==null || epCycle == "" ){
			alert("备件采购周期不能为空！");
			$("#epCycle").focus();
    		return false;
		}
		if(epMaxstock ==null || epMaxstock == "" ){
			alert("最大库存不能为空！");
			$("#epMaxstock").focus();
    		return false;
		}
		if(epMinstock ==null || epMinstock == "" ){
			alert("最小库存不能为空！");
			$("#epMinstock").focus();
    		return false;
		}
		if(epStoragelocation ==null || epStoragelocation == "" ){
			alert("存放地点不能为空！");
			$("#epStoragelocation").focus();
    		return false;
		}
		if(epMeasurementunit ==null || epMeasurementunit == "" ){
			alert("计量单位不能为空！");
			$("#epMeasurementunit").focus();
    		return false;
		}
		if(epApplicableequipment ==null || epApplicableequipment == "" ){
			alert("备件适用设备不能为空！");
			$("#epApplicableequipment").focus();
    		return false;
		}
		
     }
    function selectdept(id)
	{
		var datas = window.showModalDialog("<%=request.getContextPath() %>/resource/choose/choose_organizationIndex.jsp?temp="+Math.round(Math.random()*10000),'',"dialogWidth=900px;dialogHeight=550px");
		if(typeof(datas) == 'undefined'){
		}else{
			var json1 = eval('(' + datas + ')');
			 document.getElementById("dept_"+id).value = json1.ORG_NAME;
			 document.getElementById(id).value = json1.ORG_ID;
		}
	}
    //选择适用设备
    function equInfoSearch(equIds){
            var params = {  
                        "equIds" : encodeURIComponent(equIds)                                                              
                        }
            var postData = $("#gridTableUpdate").jqGrid("getGridParam", "postData");
            $.extend(postData, params);
			jQuery("#gridTableUpdate").jqGrid('setGridParam',
			{
				url:'<%=request.getContextPath() %>/eepRelations!queryChooseEQU.action'
			}).trigger("reloadGrid", [{page:1}]);
			$("#equUpdate").show();
			$("#equView").hide();
        } 
    function selectshebei(){
        
    	var datas = window.showModalDialog("<%=request.getContextPath() %>/view/equipmentparts_choose_ep.jsp?",window,"dialogWidth=490px;status:no;dialogHeight=400px");
    	//window.alert(datas);
    	if(datas!=null){
        	document.getElementById("epApplicableequipment").value =datas;
        	equInfoSearch(datas); 
            }	        
    }
  //选择供应商
    function selectgongyingshang(id){
    	var datas = window.showModalDialog("<%=request.getContextPath() %>/view/equipmentparts_choose_gys.jsp?",window,"dialogWidth=490px;status:no;dialogHeight=400px");
        if(datas!=null){
   		    document.getElementById(id).value = datas.ID;
   		    document.getElementById(id+"name").value = datas.GYS_NAME    		
        }
    }
	
   </script>
 	<style type="text/css">
 		body{
 			background:#ffffff; background-image:url(images/);
 		}
   		html{
		    overflow-x: hidden;
			overflow-y: hidden;
		}  	
		.formTableNew textarea{border: 1px solid #999;padding: 5px;width: 760px;-moz-border-radius: 3px;border-radius: 3px;margin-bottom: 5px;color: #666;background: url(../images/input_bg.gif) repeat-x top;}
   </style>
  </head>
  
  <body>
<form id="pageFrom" action="" enctype="multipart/form-data" method="post">
        <input type="hidden" id="flag" name="flag" />
         <input  type="hidden"  id="epApplicableequipment" maxlength="50" name="epApplicableequipment" value="${ep.epApplicableequipment}" />
  		<table width="100%" border="0" align="center" cellpadding="5" cellspacing="5" class="formTableNew">
  		   <input id="id"  type="hidden" name="id" value="${ep.id}"/>
  			<tr>
  			  <td align="right">仓库名称（部门）：</td>
  			  <td align="left">
  			  <input type="hidden" id="epStorehouse" name="epStorehouse" value="${epStorehouseid}"/>
              <input type="text" readonly style="border: 1px solid #999;padding: 5px;width: 250px;"   id="dept_epStorehouse" name="dept_epStorehouse" value="${ep.epStorehouse}" class='easyui-validatebox'  required missingMessage='必填'/>
              <img src="<%=request.getContextPath() %>/images/xh.png"  align="absmiddle"></img>
  	          <img src="<%=request.getContextPath() %>/web/images/form_icon_1.gif" style="cursor:hand; vertical-align: middle;" onclick="selectdept('epStorehouse')" />
  			  </td>
  			  <td align="right">备件代码：</td>
  			  <td align="left" colspan="2">
  			    <input  type="text"  id="epCode" maxlength="50" name="epCode" value="${ep.epCode}"  style="border: 1px solid #999;padding: 5px;width: 250px; "  />
  			  	 <img src="<%=request.getContextPath() %>/images/xh.png"  align="absmiddle"></img>
  			  </td>
  			  </tr>
  			  <tr>
  			  <td align="right">备件名称：</td>
  			  <td align="left">
  			    <input  type="text"  id="epName" maxlength="50" name="epName" value="${ep.epName}"  style="border: 1px solid #999;padding: 5px;width: 250px; "  />
  			  	 <img src="<%=request.getContextPath() %>/images/xh.png"  align="absmiddle"></img>
  			  </td>
  			  <td align="right">备件属性：</td>
  			  <td align="left" colspan="2">
  			  	<select id="epProperty" class='fselect' name="epProperty"  style="border: 1px solid #999;padding: 5px;width: 250px;height:27px;"  >
                <option value="随机备件">随机备件</option>
                <option value="外购备件">外购备件</option>
                <option value="委外备件">委外备件</option>
                <option value="回收备件">回收备件</option>
              </select></td> 
  			  </td>
  			  </tr>
  			  <tr>
  			  <td align="right">备件等级：</td>
  			  <td align="left">
  			  	<select  class='fselect'  id="epLevel" maxlength="50" name="epLevel"  style="border: 1px solid #999;padding: 5px;width: 250px;height:27px;"  />
  			    <option value="A">A</option>
                <option value="B">B</option>
                <option value="C">C</option>
  			    </select>
  			  </td>
  			  <td align="right">规格型号：</td>
  			  <td align="left" colspan="2">
  			    <input  type="text"   id="epGuige" maxlength="50" name="epGuige" value="${ep.epGuige}"  style="border: 1px solid #999;padding: 5px;width: 250px; "  />
  			  	  <img src="<%=request.getContextPath() %>/images/xh.png"  align="absmiddle"></img>
  			  </td>
  			  </tr>
  			  <tr>
  			  <td align="right">备件品牌：</td>
  			  <td align="left">
  			    <input  type="text"  id="epBrand" maxlength="50" name="epBrand" value="${ep.epBrand}"  style="border: 1px solid #999;padding: 5px;width: 250px; "  />
  			  	  <img src="<%=request.getContextPath() %>/images/xh.png"  align="absmiddle"></img>
  			  </td>
  			  <td align="right">供应商：</td>
  			  <td align="left" colspan="2"> 
  			  	<input  type="text" readonly  id="epSuppliername" maxlength="50" name="epSuppliername" value="${ep.epSupplier}"  style="border: 1px solid #999;padding: 5px;width: 210px; "  class='easyui-validatebox'  required missingMessage='必填'/>
  			    <input  type="hidden"  id="epSupplier" maxlength="50" name="epSupplier" value="${epSupplierid}"   style="border: 1px solid #999;padding: 5px;width: 250px; "  />
  			  	<img src="<%=request.getContextPath()%>/images/xh.png" align="absmiddle"></img>
				<img src="<%=request.getContextPath()%>/web/images/form_icon_1.gif" style="cursor:hand; vertical-align: middle;" onclick="selectgongyingshang('epSupplier')" />	
  			  </td>
  			  </tr>
  			  <tr>
  			  <td align="right">平均价格(元)：</td>
  			  <td align="left">
  			    <input  type="text"  id="epAverageprice" maxlength="50" name="epAverageprice" value="${ep.epAverageprice}"  class="easyui-numberbox" precision="3" max="99999.999"  style="border: 1px solid #999;padding: 5px;width: 250px; "  class='easyui-validatebox'  required missingMessage='必填,请输入数字'  />
  			  	 <img src="<%=request.getContextPath() %>/images/xh.png"  align="absmiddle"></img>
  			  </td>
  			  <td align="right">平均采购周期(天)：</td>
  			  <td align="left" colspan="2">
  			    <input  type="text" id="epCycle" maxlength="50" name="epCycle" value="${ep.epCycle}"  class="easyui-numberbox"  style="border: 1px solid #999;padding: 5px;width: 250px; "  class='easyui-validatebox'  required missingMessage='必填,请输入数字'  />
  			  	 <img src="<%=request.getContextPath() %>/images/xh.png"  align="absmiddle"></img>
  			  </td>
  			  </tr>
  			   <tr>
  			  <td align="right">最大库存：</td>
  			  <td align="left">
  			    <input  type="text"  id="epMaxstock" maxlength="50" name="epMaxstock" value="${ep.epMaxstock}" class="easyui-numberbox"  style="border: 1px solid #999;padding: 5px;width: 250px; "  class='easyui-validatebox'  required missingMessage='必填,请输入数字'  />
  			  	 <img src="<%=request.getContextPath() %>/images/xh.png"  align="absmiddle"></img>
  			  </td>
  			  <td align="right">最小库存：</td>
  			  <td align="left" colspan="2">
  			    <input  type="text"  id="epMinstock" maxlength="50" name="epMinstock" value="${ep.epMinstock}" class="easyui-numberbox"  style="border: 1px solid #999;padding: 5px;width: 250px; "  class='easyui-validatebox'  required missingMessage='必填,请输入数字' />
  			  	 <img src="<%=request.getContextPath() %>/images/xh.png"  align="absmiddle"></img>
  			  </td>
  			  </tr>
  			   <tr>
  			  <td align="right">实际库存：</td>
  			  <td align="left">
  			    <input  type="hidden"  id="epActualstock" maxlength="50" name="eepActualstock" value="${ep.epActualstock}"  style="border: 1px solid #999;padding: 5px;width: 250px; "  />
  			  	<input  type="text"  disabled="disabled" id="epActualstock1" maxlength="50" name="epActualstoc1" value="${ep.epActualstock}"  style="border: 1px solid #999;padding: 5px;width: 250px; "  /> 
  			  </td>
  			  <td align="right">计量单位：</td>
  			  <td align="left" colspan="2">
  			    <input  type="text"  id="epMeasurementunit" maxlength="50" name="epMeasurementunit" value="${ep.epMeasurementunit}"  style="border: 1px solid #999;padding: 5px;width: 250px; "  />
  			  	 <img src="<%=request.getContextPath() %>/images/xh.png"  align="absmiddle"></img>
  			  </td>
  			  </tr>
  			  <!--   <tr>
  			  <td align="right">适用设备名称：</td>
  			  <td align="left">
  			    <input  type="text" readonly id="epApplicableequipment" maxlength="50" name="ep.epApplicableequipment" value="${ep.epApplicableequipment}"  style="border: 1px solid #999;padding: 5px;width: 250px; "  />
  			  	 
  			  </td>
  			  <td align="right">适用设备编号：</td>
  			  <td align="left">
  			    <input  type="text" readonly id="epApplicableequipmentid" maxlength="50" name="ep.epApplicableequipmentid" value="${ep.epApplicableequipmentid}"  style="border: 1px solid #999;padding: 5px;width: 250px; "  />
  			  	 
  			  </td>
  			  </tr>
  			  -->
  			   <tr>
  			  <td align="right">库存状态提醒：</td>
  			  <td align="left">
  			     <select  class='fselect'  id="epStockstate" maxlength="50" name="epStockstate"  style="border: 1px solid #999;padding: 5px;width: 250px;height:27px;"  />
  			    <option value="是">是</option>
                <option value="否">否</option>
  			    </select>
  			  </td>
  			  <td align="right">存放地点：</td>
  			  <td align="left" colspan="2">
  			    <input  type="text"  id="epStoragelocation" maxlength="50" name="epStoragelocation" value="${ep.epStoragelocation}"  style="border: 1px solid #999;padding: 5px;width: 250px;"  />
  			  	 <img src="<%=request.getContextPath() %>/images/xh.png"  align="absmiddle"></img>
  			  </td>
  			  </tr>
  			   <tr>
  			   
  			  <td align="right">适用设备：<br/><br/>
  			  <img src="<%=request.getContextPath()%>/images/xh.png" align="absmiddle"></img>
  			  <img src="<%=request.getContextPath()%>/web/images/form_icon_1.gif" style="cursor:hand; vertical-align: middle;" onclick="selectshebei()" />&nbsp;&nbsp;&nbsp;&nbsp;
  			  </td>
  			   <td align="left" colspan="2" id="equView">
  		        <table  id="gridTable" ></table>
                <div id="gridPager" ></div>          
  			  </td>
  			  <td align="left" colspan="2" id="equUpdate">
  		        <table  id="gridTableUpdate" ></table>
                <div id="gridUpdatePager" ></div>            

  			  </td>
  			  <td align="right">备注：</td>
  			  <td align="left" >
  			  	<textarea rows="9" cols="1" class='ftextarea' id="epRemark" name="epRemark" value="${ep.epRemark}" style='border: 1px solid #999;padding: 5px;width:190px' ></textarea>
  			  </td>
  			  </tr>		 			
		</table>
		<table width="100%" border="0" align="center" class="formTableNew">
		  <tr>
			<td align="center">
		    	<input type="button" id="closeBtn" value="关闭" class="form_bt_grey" />
		    	<input id="saveBtn" type="button" value="保存"  class="form_bt_orange" />
		    </td>
		  </tr>
		</table>
	<!--表单结束-->
	</form>
  </body>
</html>
